﻿/// <reference path="../../release/ajaxstack-core.js"/>
/// <reference path="../../release/jsApp.js"/>

function MenuController(app, tagId)
{
	MenuController.$baseConstructor.call(this, app, tagId);

	this.links = {
		home: { label: 'Home' },
		start: {
			label: 'Getting Started',
			subMenu: {
				startProjectLayout: { label: 'Project Layout' }
			}
		},
		ajaxExamples: { label: 'Ajax Examples' },
		support: { label: 'Help and Support' }
	};
	
}
MenuController.extend(UiController, { type: 'MenuController' },
{
	loadPath: function(path)
	{
		var html = "";
		O.each(this.links, function(name, menuItem)
		{
			var selected = path && path.nameEquals(name) ? 'selected' : '';

			html += H.li(H.navLink({ action: name, 'class': selected }, menuItem.label));

			if (menuItem.subMenu)
			{
				html += H.ul({
					dataSource: menuItem.subMenu,
					onItemDataBound: function(subMenuName, subMenuItem) 
					{
						return H.li(H.navLink({ action: subMenuName }, subMenuItem.label));
					}
				})
			}
		});

		this.render(H.ul({ 'class': 'nav' }, html));
	}
});
